package com.hqyj.javaSpringBoot.modules.test.controller;

import com.hqyj.javaSpringBoot.modules.test.entity.Country;
import com.hqyj.javaSpringBoot.modules.test.service.CountryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api")
public class CountryController {
    @Autowired
    private CountryService countryService;

    /**
     * localhost/api/country/522
     */
    @GetMapping("/country/{countryId}")
    public Country getCountryByCountryId(@PathVariable int countryId) {
        return countryService.getCountryByCountryId(countryId);
    }

    /**
     * localhost/api/country?countryName=China&localCountryName=zhongquo
     * 注解@RequestParam：用于将请求参数 countryName=China&localCountryName=zhongquo
     * 绑定到你控制器的方法参数上@RequestParam String countryName,@RequestParam String localCountryName)
     * （是springmvc中接收普通参数的注解）
     */
    @GetMapping("/country")
    public Country getCountryByCountryName(@RequestParam String countryName,
                                           @RequestParam String localCountryName) {
        return countryService.getCountryByCountryName(countryName, localCountryName);
    }
}
